<template>
	<view class="content">
		<u-navbar
		:background="background" title="提现"
		title-color="#ffffff"
		back-icon-color="#ffffff"
		:borderBottom="false"
		>
		</u-navbar>
		<view class="recharge-bg">
			
		</view>
		<view class="recharge-content">
			<view class="coin-history" hover-class="hover-transform1" @tap.stop="getHistory">
				提现记录
			</view>
			<view class="coin-nav">
				<block v-for="(item,index) in conisList" :key="index">
					<view class="coin-nav-i" :class="{'active':navIndex==index}" @tap.stop="chooseNav(index)">{{item.title_en}}</view>
				</block>
				
				<!-- <view class="coin-nav-i" :class="{'active':navIndex==1}" @tap.stop="chooseNav(1)">USDT2</view>
				<view class="coin-nav-i" :class="{'active':navIndex==2}" @tap.stop="chooseNav(2)">RLD</view>
				<view class="coin-nav-i" :class="{'active':navIndex==3}" @tap.stop="chooseNav(3)">RLD2</view> -->
			</view>
			
			
			<view class="recharge-t">
				<text class="recharge-t-t">请输入提现数量</text>
				<view class="recharge-content-t">
					<input type="number" placeholder="请输入提现数量" v-model="num" placeholder-style="font-size:28rpx">
					<text>{{coniInfo.title_en}}</text>
				</view>
				
			</view>
			<view class="recharge-tips">
				当前可用资产{{db_banlance_num || '0'}}{{coniInfo.title_en}}
				
				<!-- db4_balance  da11_balance  db1_balance -->
			</view>
			<view class="recharge-btn">
				<button @tap.stop="addressCheck">确定</button>
			</view>
		</view>
		


		<u-popup v-model="showPopule1" mode="center" :safeAreaInsetBottom="true" :mask-close-able="true">
			<view class="popule-loading">
				<u-loadmore :status="status" bgColor="#000000" :loading-text="loadingText" :loadmore-text="loadmoreText"
					:nomore-text="nomoreText" />

			</view>

		</u-popup>
		<u-action-sheet :list="selectList" @click="click" v-model="show" :cancelText="i18n.cancel"></u-action-sheet>
		<u-top-tips ref="message" :type="types" zIndex="999" :navbar-height="statusBarHeight + navbarHeight">
		</u-top-tips>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapMutations
	} from "vuex";
	import {
		pageto,
		showToast,
		fetch,
		forceUpdate
	} from '@/common/js/util.js'
	export default {
		data() {
			return {
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				background: "linear-gradient(to right ,#F5C249, #947222)",
				// 导航栏内容区域高度，不包括状态栏高度在内
				navbarHeight: 44,
				types: '',
				show: false,
				selectList: [],
				indexOne: 0,
				num: '',
				timer: '',
				status: 'loading',
				loadingText: 'trying to load',
				loadmoreText: 'Pull up gently',
				nomoreText: 'really no more',
				showPopule1: false,
				navIndex:0,
				db1_balance:'',
				db11_balance:'',
				db3_balance:'',  
				db4_balance:'',  
				showLoad:false,
				conisList:[],
				coniInfo:{},
				db_banlance_num:'',
				coinITem:[]
			}
		},
		components: {

		},
		computed: {
			i18n() {
				return this.$t('message')
			},
			...mapGetters([
				'getRequestUrl',
				'getLangType',
				'getLogin',
				'getLoginInfo',
				'getCz_address'
			])
		},
		onUnload() {
			clearInterval(this.timer)
			this.timer = null
			this.timer = ''
		},
		onHide() {
			clearInterval(this.timer)
			this.timer = null
			this.timer = ''
		},
		onShow() {
			this.getConis()
			// this.getMine()
			this.showPopule1 = false;
			// forceUpdate(this.getLangType);
		},
		onLoad() {

		},
		methods: {
			getConis(){
				this.showLoad = true;
				fetch('/api/wallet/coins', '', "post").then(res=>{
					this.showLoad = false;
					if(res.data.code){
						
						this.conisList = res.data.data
						this.coniInfo = this.conisList[0]
						this.db_banlance_num =this.coniInfo.balance
					}
				}).catch(err=>{
					this.showLoad = false;
				})
			},
			getMine(){  
				this.showLoad = true;
				fetch('/api/index/index', '', "post").then(res=>{
					this.showLoad = false;
					if(res.data.code){
						this.db1_balance = res.data.data.db1_balance
						this.db3_balance = res.data.data.db3_balance
						this.db4_balance = res.data.data.db4_balance
						this.db11_balance = res.data.data.db11_balance
						// this.db_banlance_num = `this.db${this.coniInfo.id}_balance` 
						let list = [
							{token_id:1,db_balance:res.data.data.db1_balance},
							{token_id:3,db_balance:res.data.data.db3_balance},
							{token_id:4,db_balance:res.data.data.db4_balance},
							{token_id:11,db_balance:res.data.data.db11_balance}
						]
						this.coinITem = list
						let info = list.filter(item=>item.token_id==this.coniInfo.id)
						
						this.db_banlance_num =info[0].db_balance
						// var str = “Hello World!”;
						// if(str.includes(“World”)){
						// }
					}
				}).catch(err=>{
					this.showLoad = false;
				})
			},
			getHistory(){
				uni.navigateTo({
					url:'/pages/coin-list/coin-list'
				})
			},
			getCoins(){
				let data = {
					number:this.num,
					token_id:this.conisList[this.navIndex].id
					// type:2,
					// yzm:this.yzm
				}
				
				
				if(this.isCheck) return
				this.isCheck  = true;
				// this.laoding = true;
				fetch('/api/wallet/transfer',data,'POST').then(res=>{
					this.isCheck=false;
					this.showPopule = false;this.num = ''
					if(res.data.code==1){
						this.showTips(res.data.msg,'success')
						this.getMine()
					}else{
						this.showTips(res.data.msg,'error')
					}
					
					
				})
			},
			async addressCheck() {
						if(!this.num || this.num==null){
							this.showTips('请输入数量','error')
							return 
						}
						let _this = this
			          let message='提现验证';
			          let address = this.getLoginInfo.address;
			          ethereum.request({
			              method: "personal_sign",
			              params: [message, address],
			          }).then((signature) => {
				// _this.signature = signature
						// _this.showTips(signature,'success')
			              // 
			// console.log(signature);
							_this.showPopule = false
							// _this.number = ''
							if(signature && Number(signature.length)>=132){
								_this.getCoins()
								return
							}
			              
			              //有这个值证明签名了  就可以进行提现操作了
			              //这里进行提现操作
			
			          })
			          .catch((err) => {
						_this.num = ''
			              // 异常  弹个窗
						_this.showTips(_this.getLangType=='en'?' 你无权使用':'你无权使用','success')
			//               alert('你无权使用');
			          });
			          
			
			        },
			chooseNav(index){
				this.navIndex=index
				this.coniInfo = this.conisList[index]
console.log(this.coniInfo);
			
				this.db_banlance_num =this.conisList[index].balance
			},
			//获取余额
			async handleBalanceTap() {
				let that = this
				that.showPopule1 = true;
				const contractAbi = [{"anonymous": false,"inputs": [{"indexed": true,"internalType": "address","name": "owner","type": "address"},{"indexed": true,"internalType": "address","name": "spender","type": "address"},{"indexed": false,"internalType": "uint256","name": "value","type": "uint256"}],"name": "Approval","type": "event"},{"anonymous": false,"inputs": [{"indexed": false,"internalType": "uint8","name": "version","type": "uint8"}],"name": "Initialized","type": "event"},{"anonymous": false,"inputs": [{"indexed": true,"internalType": "address","name": "previousOwner","type": "address"},{"indexed": true,"internalType": "address","name": "newOwner","type": "address"}],"name": "OwnershipTransferred","type": "event"},{"anonymous": false,"inputs": [{"indexed": true,"internalType": "address","name": "from","type": "address"},{"indexed": true,"internalType": "address","name": "to","type": "address"},{"indexed": false,"internalType": "uint256","name": "value","type": "uint256"}],"name": "Transfer","type": "event"},{"inputs": [{"internalType": "address","name": "owner","type": "address"},{"internalType": "address","name": "spender","type": "address"}],"name": "allowance","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "spender","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "approve","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "account","type": "address"}],"name": "balanceOf","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "burn","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "canExchange","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "canTransfer","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "decimals","outputs": [{"internalType": "uint8","name": "","type": "uint8"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "spender","type": "address"},{"internalType": "uint256","name": "subtractedValue","type": "uint256"}],"name": "decreaseAllowance","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "exchange","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "exchangeAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "getOwner","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "spender","type": "address"},{"internalType": "uint256","name": "addedValue","type": "uint256"}],"name": "increaseAllowance","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "initialize","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "","type": "address"}],"name": "inviterInfo","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "name","outputs": [{"internalType": "string","name": "","type": "string"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "oldAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "owner","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "pairAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "renounceOwnership","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "retrieveAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "bool","name": "canExchange_","type": "bool"}],"name": "setCanExchange","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "bool","name": "canTransfer_","type": "bool"}],"name": "setCanTransfer","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "exchangeAddress_","type": "address"}],"name": "setExchangeAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "pairAddress_","type": "address"}],"name": "setPairAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "retrieveAddress_","type": "address"}],"name": "setRetrieveAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "transFeeAddress_","type": "address"}],"name": "setTransFeeAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "user_","type": "address"},{"internalType": "bool","name": "in_","type": "bool"}],"name": "setTransFeeWhiteList","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "user_","type": "address"},{"internalType": "bool","name": "in_","type": "bool"}],"name": "setTransLimitWhiteList","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "symbol","outputs": [{"internalType": "string","name": "","type": "string"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "totalSupply","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "transFeeAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "","type": "address"}],"name": "transFeeWhiteList","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "","type": "address"}],"name": "transLimitWhiteList","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "to","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "transfer","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "from","type": "address"},{"internalType": "address","name": "to","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "transferFrom","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "newOwner","type": "address"}],"name": "transferOwnership","outputs": [],"stateMutability": "nonpayable","type": "function"}]
				//获取钱包地址
				const accounts = await web3js.eth.getAccounts();
				//获取钱包里的余额
				const balance = await web3js.eth.getBalance(accounts[0]);
				let num = that.num
				let numt = web3js.utils.toWei(`${num}`, "ether")
				// console.log(numt, 'numt');
				let toAddress = that.getCz_address;
				let meta = new web3js.eth.Contract(contractAbi, '0x15fC7F4dE5c9C196464b0e2862007acb9E0F29B9');

				let formAddress = that.getLoginInfo.address
				let res = null
				try {
					res = await meta.methods.transfer(toAddress, numt).send({
						from: formAddress
					})
				} catch (e) {}
				if (res && res.transactionHash) {
					//ajax修改状态和交易hash
					const sendData = {
						id: that.getLoginInfo.id,
						token: that.getLoginInfo.token,
						lang_type: 1,
						hash: res.transactionHash
					}

					var count = 0

					that.timer = setInterval(() => {
						count++

						if (count >= 25) {
							that.showPopule1 = false;
							uni.hideLoading()
							that.timer = null
							clearInterval(that.timer)
							that.timer = ''
							return
						}
						fetch('/api/wallet/checkCz', sendData, 'post').then(result => {

							if (result.data.code == 1) {
								if (result.data.data.status == 1) {
									that.showPopule1 = false;
									that.showTips('成功', 'success')
									that.timer = null
									clearInterval(that.timer)
									that.timer = ''
								}
							}
						})
					}, 5000)
				} else {
					that.showPopule1 = false;
					that.showTips('用户已拒绝', 'error')
				}
			},
			async handleBalanceTap1() {
				let that = this
				that.showPopule1 = true;
				const contractAbi = [{"anonymous": false,"inputs": [{"indexed": true,"internalType": "address","name": "owner","type": "address"},{"indexed": true,"internalType": "address","name": "spender","type": "address"},{"indexed": false,"internalType": "uint256","name": "value","type": "uint256"}],"name": "Approval","type": "event"},{"anonymous": false,"inputs": [{"indexed": false,"internalType": "uint8","name": "version","type": "uint8"}],"name": "Initialized","type": "event"},{"anonymous": false,"inputs": [{"indexed": true,"internalType": "address","name": "previousOwner","type": "address"},{"indexed": true,"internalType": "address","name": "newOwner","type": "address"}],"name": "OwnershipTransferred","type": "event"},{"anonymous": false,"inputs": [{"indexed": true,"internalType": "address","name": "from","type": "address"},{"indexed": true,"internalType": "address","name": "to","type": "address"},{"indexed": false,"internalType": "uint256","name": "value","type": "uint256"}],"name": "Transfer","type": "event"},{"inputs": [{"internalType": "address","name": "owner","type": "address"},{"internalType": "address","name": "spender","type": "address"}],"name": "allowance","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "spender","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "approve","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "account","type": "address"}],"name": "balanceOf","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "burn","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "canExchange","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "canTransfer","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "decimals","outputs": [{"internalType": "uint8","name": "","type": "uint8"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "spender","type": "address"},{"internalType": "uint256","name": "subtractedValue","type": "uint256"}],"name": "decreaseAllowance","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "exchange","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "exchangeAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "getOwner","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "spender","type": "address"},{"internalType": "uint256","name": "addedValue","type": "uint256"}],"name": "increaseAllowance","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "initialize","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "","type": "address"}],"name": "inviterInfo","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "name","outputs": [{"internalType": "string","name": "","type": "string"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "oldAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "owner","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "pairAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "renounceOwnership","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "retrieveAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "bool","name": "canExchange_","type": "bool"}],"name": "setCanExchange","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "bool","name": "canTransfer_","type": "bool"}],"name": "setCanTransfer","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "exchangeAddress_","type": "address"}],"name": "setExchangeAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "pairAddress_","type": "address"}],"name": "setPairAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "retrieveAddress_","type": "address"}],"name": "setRetrieveAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "transFeeAddress_","type": "address"}],"name": "setTransFeeAddress","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "user_","type": "address"},{"internalType": "bool","name": "in_","type": "bool"}],"name": "setTransFeeWhiteList","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "user_","type": "address"},{"internalType": "bool","name": "in_","type": "bool"}],"name": "setTransLimitWhiteList","outputs": [],"stateMutability": "nonpayable","type": "function"},{"inputs": [],"name": "symbol","outputs": [{"internalType": "string","name": "","type": "string"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "totalSupply","outputs": [{"internalType": "uint256","name": "","type": "uint256"}],"stateMutability": "view","type": "function"},{"inputs": [],"name": "transFeeAddress","outputs": [{"internalType": "address","name": "","type": "address"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "","type": "address"}],"name": "transFeeWhiteList","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "","type": "address"}],"name": "transLimitWhiteList","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "view","type": "function"},{"inputs": [{"internalType": "address","name": "to","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "transfer","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "from","type": "address"},{"internalType": "address","name": "to","type": "address"},{"internalType": "uint256","name": "amount","type": "uint256"}],"name": "transferFrom","outputs": [{"internalType": "bool","name": "","type": "bool"}],"stateMutability": "nonpayable","type": "function"},{"inputs": [{"internalType": "address","name": "newOwner","type": "address"}],"name": "transferOwnership","outputs": [],"stateMutability": "nonpayable","type": "function"}];
				//获取钱包地址
				const accounts = await web3js.eth.getAccounts();
				//获取钱包里的余额
				const balance = await web3js.eth.getBalance(accounts[0]);
				let num = that.num
				let numt = web3js.utils.toWei(`${num}`, "ether")
				let toAddress = that.getCz_address;
				// let meta = new web3js.eth.Contract(contractAbi,'0x55d398326f99059ff775485246999027b3197955');
				let meta = new web3js.eth.Contract(contractAbi, '0x15fC7F4dE5c9C196464b0e2862007acb9E0F29B9');
				let formAddress = that.getLoginInfo.address
				let res = null
				try {
					res = await meta.methods.transfer(toAddress, numt).send({
						from: formAddress
					})

				} catch (e) {}
				if (res && res.transactionHash) {
					//ajax修改状态和交易hash
					const sendData = {
						id: that.getLoginInfo.id,
						token: that.getLoginInfo.token,
						lang_type: 1,
						hash: res.transactionHash
					}

					var count = 0

					that.timer = setInterval(() => {
						count++

						if (count >= 25) {
							that.showPopule1 = false;
							uni.hideLoading()

							clearInterval(that.timer)
							that.timer = null
							that.timer = ''
							return
						}
						fetch('/api/wallet/checkCz', sendData, 'post').then(result => {

							if (result.data.code == 1) {

								if (result.data.data.status == 1) {
									that.showPopule1 = false;
									that.showTips('成功', 'success')

									clearInterval(that.timer)
									that.timer = null
									that.timer = ''
								}
							} else {

								// this.showTips(result.data.message,error)
							}
						})
					}, 5000)
				} else {
					that.showPopule1 = false;
					that.showTips('用户已拒绝', 'error')
					// uni.showToast({
					// 	title:'我拒绝了'
					// })
				}



				return
				web3js.eth.sendTransaction({
					gas: 21000,
					gasPrice: 5000000000,
					from: accounts[0],
					to: toAddress,
					value: amount
				}, (err, result) => {
					// console.log("转账Hash=", result)
				})
				// const enable = await ethereum.enable();
				//     console.log(enable,11)




			},
			async buy() {
				if (Number(this.num) <= 0) {
					this.showTips(this.getLangType == 'en' ? 'Please enter the correct number' : '请输入正确数字', 'error')
					return
				}

				this.handleBalanceTap1()
				return

				// uni.navigateTo({
				// 	url:"./recharge-list?number="+this.num
				// })

				let res = null
				try {
					res = await web3js.send2(this.vipInfo.vipnft_address, this.vipInfo.price)
				} catch (e) {
					if (this.timer) {
						uni.hideLoading()
						clearInterval(this.timer)
					}
				}

				// console.log(res);

				if (res && res.transactionHash) {
					//ajax修改状态和交易hash
					const sendData = {
						id: this.userInfo.id,
						token: this.userInfo.token,
						lang_type: 1,
						hash: res.transactionHash
					}

					var count = 0

					this.timer = setInterval(() => {
						count++
						if (count >= 25) {
							if (!this.MintSuccess) {
								// uni.showToast({
								//   title: 'Mint失败',
								//   icon: 'none',
								//   mask: true
								// })
							}

							uni.hideLoading()

							clearInterval(this.timer)
							return
						}

						this.checkOperation(sendData, code => {
							if (code === 1 && count == 24) {
								// uni.showToast({
								//   title: '解锁失败',
								//   icon: 'none',
								//   mask: true
								// })
							}
						})
					}, 5000)
				} else {
					alert('失败')
				}


			},
			clickOne(index) {
				this.indexOne = index
				switch (index) {
					case 1:
						this.num = 300
						break;
					case 2:
						this.num = 500
						break;
					case 3:
						this.num = 1000
						break;
					case 4:
						this.num = 2000
						break;
					case 5:
						this.num = 5000
						break;
					case 6:
						this.num = 10000
						break;
					case 7:
						this.num = 50000
						break;
					case 8:
						this.num = 100000
						break;
				}
			},
			showTips(msg, type) {
				// <!-- type值可选的有primary(默认)、success、info、warning、error -->
				this.$refs.message.type = type
				this.$refs.message.show({
					title: msg
				});
			},

		}
	}
</script>

<style scoped lang="scss">
	.coin-history{
		display: flex;
		justify-content: flex-end;
		font-size: 28rpx;
		color: #F5C249;
		line-height: 34rpx;
		padding: 32rpx 30rpx;
	}
	.coin-nav{
		// background: #16171d;
		// border-radius: 8rpx;
		width: 400rpx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		margin-bottom: 80rpx;
		.coin-nav-i{
			text-align:center;
			font-size: 28rpx;
			width: 200rpx;
			line-height: 66rpx;
			color: $white;
			
			&.active{
				position: relative;
				color: #F4C154;
				&::after{
					border-radius: 8rpx;
					background: #F4C154;
					width: 40rpx;
					height: 10rpx;
					content:'';
					position: absolute;
					left: 50%;
					transform: translateX(-50%);
					bottom: 0;
				}
				
			}
		}
	}
	.recharge-bg{
		background:linear-gradient(to right ,#F5C249, #947222) ;
		height: 320rpx;
		width: 750rpx;
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		z-index: 2;
	}
	.popule-loading {
		width: 300rpx;
		height: 200rpx;
		border-radius: 20rpx;
		// padding: 150rpx 0;
		background: $black;
		opacity: 0.9;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.recharge-content {
		position: absolute;
		left: 50%;
		top: 108rpx;
		z-index: 8;
		width: 686rpx;
		border-radius: 10rpx;
		background: #21242D;
		// background: $white;
		// padding: 28rpx 0 0;
		transform: translateX(-50%);
		.recharge-t {
			padding: 0 30rpx;
			.recharge-t-t {
				font-size: 34rpx;
				color: $white;
				display: block;
				line-height: 48rpx;
				margin-bottom: 34rpx;
			}
			.recharge-content-t{
				background: #384156;
				display: flex;
				align-items: center;
				border-radius: 6rpx;
				padding:0 20rpx;
				margin-bottom: 18rpx;
				text{
					font-size: 34rpx;
					color: $white;
					text-align: center;
					width: 92rpx;
				}
				input {
					flex: 1;
					line-height: 92rpx;
					font-size: 38rpx;
					height: 92rpx;
					color: $white;
					// border-bottom: 1rpx solid #dcdcdc;
				}
			}
			
		}

		.recharge-tips {
			font-size: 26rpx;
			color: $white;
			padding: 0 30rpx;
			line-height: 50rpx;
			margin-bottom: 58rpx;
		}

		.recharge-list {
			margin-top: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;

			.recharge-item {
				width: 23%;
				text-align: center;
				line-height: 66rpx;
				border: 1rpx solid #dcdcdc;
				color: #666;
				font-size: 28rpx;
				margin-bottom: 10rpx;

				&.active {
					background: #0273FE;
					color: $white;
					border: none;
					;
				}
			}
		}




	}

	.recharge-btn {
		padding: 0 30rpx;
		margin-bottom: 60rpx;
		button {
			border-radius: 8rpx;
			background: #F5C249;
			color: $white;
			line-height: 108rpx;
			height: 108rpx;
			font-size: 34rpx;
			// width: 690rpx;
		}
	}
</style>
